var rest = (x) => {
    //判空
    if(typeof x != 'number'){
        return;
    }
    //设置边界
    const max = Math.pow(2,31) - 1;
    const min = -1 * Math.pow(2,31);

    //运算
    let num = Math.abs(x)
    let res = 0
    while(num != 0){
        res = (num % 10) + res * 10
        num = Math.floor(num/10)
    }
    let result = 0

    //加正负号
    x > 0
        ?  result = res
        :  result = -1 * res
    //判断是否在min - max范围,并返回
    if(result >= min && result <= max){
        return result
    }
    return 0;
}

var a = rest(-1234)
console.log(a);
